package com.intexh.quickandroid.module.chat.ui.messageItemView;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.widget.ImageView;

import com.intexh.quickandroid.R;
import com.intexh.quickandroid.module.chat.ChatHelper;
import com.intexh.quickandroid.module.chat.bean.ChatMessage;
import com.intexh.quickandroid.module.chat.ui.face.FaceAdapter;
import com.intexh.quickandroid.module.chat.ui.face.FaceParser;


/**
 * Created by engine on 13-12-17.
 */
public class FaceMessageItem extends AbsChatItem {

    public FaceMessageItem(Context context, ChatMessage message, boolean needTime) {
        this(context,message,needTime,false);
    }

    public FaceMessageItem(Context context, ChatMessage message, boolean needTime, boolean isAllOnLeft) {
        super(context);

        this.mNeedTime = needTime;
        this.mMessage = message;
        this.mContext = context;

        if (ChatHelper.getInstance().getUserInfo().getUid().equals(message.getUid()) && !isAllOnLeft) {//发出去的
            LayoutInflater.from(context).inflate(R.layout.message_face_to, this);
        } else {//接收到的
            LayoutInflater.from(context).inflate(R.layout.message_face_from, this);
        }
        setLayout();
    }

    private void setLayout() {
        setCommonLayout();

        final ImageView contentTextView = (ImageView) findViewById(R.id.session_content);
        String msg = mMessage.getContent();
        if (!TextUtils.isEmpty(msg)) {
            String path = FaceParser.getKeyByValue(mContext, msg.substring(1, msg.length() - 1));
            contentTextView.setImageDrawable(FaceAdapter.getDrawableByAssets(path, mContext));
        }
    }


}
